<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>144-动画-减速动画处理透明度.html</title>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
		#line{
			width: 200px;
			height: 200px;
			background: skyblue;
		}
		#box{
			width: 200px;
			height: 200px;
			background: pink;
			opacity: 0.5;
		}

	</style>
</head>
<body>
	<button id="btn">开始</button>
	<div id="box"></div>
	<div id="line"></div>
</body>
<script>
	var oBtn = document.getElementById('btn');
	var oBox = document.getElementById('box');
	var timer = 0;
	oBtn.onclick = function(){
		clearInterval(timer);
		var iSpeed =0;
		timer = setInterval(function(){
			var currentVal = parseFloat(getComputedStyle(oBox,false)["opacity"]);
			currentVal = Math.round(currentVal*100);
			iSpeed = (100 - currentVal)/10;
			iSpeed = iSpeed>0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
			if(!iSpeed){
				// oBox.style.opacity = 1;
				clearInterval(timer);	
			}else{
				oBox.style.opacity = (currentVal + iSpeed)/100;
			}
			console.log(currentVal,iSpeed);
		},30)
	}
	
</script>
</html>